package org.bingmaps.app;

import java.io.Serializable;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import java.lang.reflect.Method;

import javax.xml.datatype.DatatypeConstants.Field;

import locationServices.MyLocationListener;

import org.bingmaps.app.R;



import General.FTPHandle;
import General.GlobalValueClass;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.Window;


public class MainActivity extends Activity{

	
	private static LocationManager mlocManager = null;
	private static LocationListener mlocListener = null;
	public GlobalValueClass GLOBAL;
	public FTPHandle FTP;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	 super.onCreate(savedInstanceState);      
    	
    	requestWindowFeature(Window.FEATURE_NO_TITLE);
    	
    	mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);  
        mlocListener = new MyLocationListener();  
        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    	
        GLOBAL = new GlobalValueClass(mlocManager,mlocListener);
        
    	//OPTION Lock map orientation
    	setRequestedOrientation(1);
    	setContentView(R.layout.main);
    }
    
    
  //MENU
  	 @Override
  	    public boolean onCreateOptionsMenu(Menu menu) {
  	        MenuInflater inflater = getMenuInflater();
  	        inflater.inflate(R.menu.optionsmenu, menu);
  	        return true;
  	    }
  	
  	 //HANDLING MENU EVENTS
  	 @Override
  	 public boolean onOptionsItemSelected(MenuItem item) 
  	 {
  	     // Handle item selection
  	     switch (item.getItemId()) {
  	         case R.id.SENDFILES:
  	        	FTP = new FTPHandle(getApplicationContext());
  	             return true;
  	         case R.id.HELP:
  	        	msbox("Help","Help Message");
  	             return true;
  	             
  	         case R.id.ABOUT:
  	            	msbox("About","about Message");  	             
  	             return true;
  	         default:
  	             return super.onOptionsItemSelected(item);
  	     }
  	 }
    
    public void StartTracking(View view){
    	//USE API
    	Intent intent = new Intent(getApplicationContext(), WhatToTrack.class);
    	startActivity(intent);
    	finish();
    }
    
   
   public void ConsultTracks(View view){
    	//The new activity will be show to the user so that he can choose and see his tracks
    	Intent intent = new Intent(getApplicationContext(), UserTracks.class);
    	startActivity(intent);
   }
   
 //Message BOX
   public void msbox(String str,String str2)
   {
   	
       AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this); 
       dlgAlert.setTitle(str); 
       dlgAlert.setMessage(str2);
       
       dlgAlert.setPositiveButton("OK",new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int whichButton) {
           	return;
           }
       });
       dlgAlert.setCancelable(true);
       dlgAlert.create().show();
   }
	    
}